bool fun(vector<int>& nums1, vector<int>& nums2, int x) {
    int nn = 2;
    int j = 0;
    for (int i = 0; i < nums2.size(); i++) {
        while (nums1[j] + x != nums2[i]) {
            j++;
            if (nn == 0)
                return false;
            --nn;
        }
        j++;
    }
    return true;
}
class Solution {
public:
    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {
        sort(nums1.begin(), nums1.end());
        sort(nums2.begin(), nums2.end());
        int x = 1000000;
        int t = 0;
        for (int i = 0; i <= 2; i++) {
            t = nums2[0] - nums1[i];
            if (fun(nums1, nums2, t)) {
                x = min(x, t);
            }
        }
        return x;
    }
};